package _interview150;

import java.util.HashSet;

/**
 * 128. 最长连续序列
 */
public class No128 {
    public int longestConsecutive(int[] nums) {
        HashSet<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }
        int ans = 0;
        for (Integer num : set) {
            if (set.contains(num - 1)) {
                continue;
            }
            int curLen = 1;
            while (set.contains(++num)) curLen++;
            ans = Math.max(ans, curLen);
        }
        return ans;
    }
}
